rm(list=ls())

library(fixest)
library(gridExtra)
library(lme4)
library(lmerTest)
library(marginaleffects)
library(openxlsx)
library(ordinal)
library(quanteda)
library(quanteda.textmodels)
library(quanteda.textstats)
library(tidyverse)

load("democracy.RData")


### Main Manuscript ############################################################

# Figure 1: Average scores on the country level across the entire observation
# period 

load("world.Rdata")

datac <- data %>% group_by(country) %>%
  summarize(armscontrolsupport = mean(armscontrolsupport))

datac <- merge(world, datac, by.x = "sovereignt", by.y = "country")

f1 <- ggplot(data = datac) +
  geom_sf(aes(fill = armscontrolsupport)) +
  scale_fill_viridis_c(option = "magma", begin = 0.1, direction = -1) +
  coord_sf(ylim = c(-60, 85)) +
  theme(panel.background = element_blank(),
    legend.title = element_text(size = 8),
    legend.text = element_text(size = 6),
    legend.key.height = unit(0.4, "cm"),
    legend.key.width = unit(0.2, "cm")) +
  labs(fill = "Support for Arms Control")

png("figure1.png", res = 600, width = 6500, height = 2500)
f1
dev.off()


# Table 4: Effect of Liberal Democracy on Support for Different Types of Arms
# Control 

modelmain_main_all <- lmer(armscontrolsupport ~ liberaldemocracy
                           + log(gdppc) + log(tradeopenness) + conflict + region
                           + category + topic 
                           + globallyrelevant + log(salience + 1)
                           + (1 | country) + (1 | year) + (1 | repeatedres),
                           data = data)
summary(modelmain_main_all)
save(modelmain_main_all, file = "modelmain_main_all.RData")

modelmain_main_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                           + log(gdppc) + log(tradeopenness) + conflict + region
                           + category + globallyrelevant + log(salience + 1)
                           + (1 | country) + (1 | year) + (1 | repeatedres),
                           data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_main_nuc)
save(modelmain_main_nuc, file = "modelmain_main_nuc.RData")

modelmain_main_con <- lmer(armscontrolsupport ~ liberaldemocracy
                           + log(gdppc) + log(tradeopenness) + conflict + region 
                           + category + globallyrelevant + log(salience + 1)
                           + (1 | country) + (1 | year) + (1 | repeatedres),
                           data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_main_con)
save(modelmain_main_con, file = "modelmain_main_con.RData")


# Table 5: Interaction Effect Between Liberal Democracy and Share of Democratic
# Co-Sponsors on Support for Different Types of Arms Control

modelint_main_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                          * share_libdemauthors
                          + log(gdppc) + log(tradeopenness) + conflict + region
                          + category + topic 
                          + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data[data$category == "1" | data$category == "2", ])
summary(modelint_main_all)
save(modelint_main_all, file = "modelint_main_all.RData")

modelint_main_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                          * share_libdemauthors
                          + log(gdppc) + log(tradeopenness) + conflict + region
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Nuclear Weapons" 
                                      & data$category == "1" 
                                      | data$topic == "Nuclear Weapons" 
                                      & data$category == "2", ])
summary(modelint_main_nuc)
save(modelint_main_nuc, file = "modelint_main_nuc.RData")

modelint_main_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                          * share_libdemauthors
                          + log(gdppc) + log(tradeopenness) + conflict + region 
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Conventional Weapons" 
                                      & data$category == "1" 
                                      | data$topic == "Conventional Weapons" 
                                      & data$category == "2", ])
summary(modelint_main_con)
save(modelint_main_con, file = "modelint_main_con.RData")


# Figure 2: Conditional Effects of Democracy on Support for Different Types of 
# Arms Control 

marginal_all <- slopes(modelint_main_all, variables = "liberaldemocracy",
                       by = "share_libdemauthors")

marginal_nuc <- slopes(modelint_main_nuc, variables = "liberaldemocracy",
                       by = "share_libdemauthors")

marginal_con <- slopes(modelint_main_con, variables = "liberaldemocracy",
                       by = "share_libdemauthors")

f2a <- ggplot(marginal_all, aes(x = share_libdemauthors, y = estimate)) +
  geom_line() +
  geom_hline(yintercept = 0, linetype = "dashed", color = "darkgrey") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.2) +
  labs(x = "Share of Liberal Democratic Co-Sponsors",
       y = "Effect of Democracy on Support for Arms Control",
       title = "A. All") +
  scale_x_continuous(breaks = c(0, 0.25, 0.5, 0.75, 1),
                     limits = c(0, 1), expand = c(0, 0)) +
  scale_y_continuous(breaks = c(-0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2),
                     limits = c(-0.09, 0.24)) +
  theme(panel.background = element_blank()) +
  theme_classic()

f2b <- ggplot(marginal_nuc, aes(x = share_libdemauthors, y = estimate)) +
  geom_line() +
  geom_hline(yintercept = 0, linetype = "dashed", color = "darkgrey") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.2) +
  labs(x = "Share of Liberal Democratic Co-Sponsors",
       y = "Effect of Democracy on Support for Nuclear Arms Control",
       title = "B. Nuclear") +
  scale_x_continuous(breaks = c(0, 0.25, 0.5, 0.75, 1),
                     limits = c(0, 1), expand = c(0, 0)) +
  scale_y_continuous(breaks = c(-0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2),
                     limits = c(-0.09, 0.24)) +
  theme(panel.background = element_blank()) +
  theme_classic()

f2c <- ggplot(marginal_con, aes(x = share_libdemauthors, y = estimate)) +
  geom_line() +
  geom_hline(yintercept = 0, linetype = "dashed", color = "darkgrey") +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = 0.2) +
  labs(x = "Share of Liberal Democratic Co-Sponsors",
       y = "Effect of Democracy on Support for Conventional Arms Control",
       title = "C. Conventional") +
  scale_x_continuous(breaks = c(0, 0.25, 0.5, 0.75, 1),
                     limits = c(0, 1), expand = c(0, 0)) +
  scale_y_continuous(breaks = c(-0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2),
                     limits = c(-0.09, 0.24)) +
  theme(panel.background = element_blank()) +
  theme_classic()

png("figure2.png", res = 600, width = 9500, height = 3000)
grid.arrange(f2a, f2b, f2c, ncol = 3, nrow = 1)
dev.off()


### Online Appendix E: Robustness Checks - Main Effect #########################

# Table A4: No Control Variables 

modelmain_onlyre_all <- lmer(armscontrolsupport ~ liberaldemocracy
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data)
summary(modelmain_onlyre_all)
save(modelmain_onlyre_all, file = "modelmain_onlyre_all.RData")

modelmain_onlyre_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_onlyre_nuc)
save(modelmain_onlyre_nuc, file = "modelmain_onlyre_nuc.RData")

modelmain_onlyre_con <- lmer(armscontrolsupport ~ liberaldemocracy
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic 
                                         == "Conventional Weapons", ])
summary(modelmain_onlyre_con)
save(modelmain_onlyre_con, file = "modelmain_onlyre_con.RData")


# Table A5: Controlling for Nuclear Weapons Possession 

modelmain_inclnuc_all <- lmer(armscontrolsupport ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region + nuclearpower
                              + category + topic 
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data)
summary(modelmain_inclnuc_all)
save(modelmain_inclnuc_all, file = "modelmain_inclnuc_all.RData")

modelmain_inclnuc_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region + nuclearpower
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_inclnuc_nuc)
save(modelmain_inclnuc_nuc, file = "modelmain_inclnuc_nuc.RData")

modelmain_inclnuc_con <- lmer(armscontrolsupport ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region + nuclearpower
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic 
                                          == "Conventional Weapons", ])
summary(modelmain_inclnuc_con)
save(modelmain_inclnuc_con, file = "modelmain_inclnuc_con.RData")


# Table A6: Controlling for UNGA Ideal Points 

modelmain_inclid_all <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region + idealpoint
                             + category + topic
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data)
summary(modelmain_inclid_all)
save(modelmain_inclid_all, file = "modelmain_inclid_all.RData")

modelmain_inclid_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region + idealpoint
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_inclid_nuc)
save(modelmain_inclid_nuc, file = "modelmain_inclid_nuc.RData")

modelmain_inclid_con <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region + idealpoint
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic 
                                         == "Conventional Weapons", ])
summary(modelmain_inclid_con)
save(modelmain_inclid_con, file = "modelmain_inclid_con.RData")


# Table A7: Fixed Effects Models

modelmain_fe_all <- feols(armscontrolsupport ~ liberaldemocracy
                          + log(gdppc) + log(tradeopenness) + conflict
                          + category + topic
                          + globallyrelevant + log(salience + 1)
                          | country + year,
                          cluster = c("country", "year"),
                          data = data)
summary(modelmain_fe_all)
save(modelmain_fe_all, file = "modelmain_fe_all.RData")

modelmain_fe_nuc <- feols(armscontrolsupport ~ liberaldemocracy
                          + log(gdppc) + log(tradeopenness) + conflict
                          + category + globallyrelevant + log(salience + 1)
                          | country + year,
                          cluster = c("country", "year"),
                          data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_fe_nuc)
save(modelmain_fe_nuc, file = "modelmain_fe_nuc.RData")

modelmain_fe_con <- feols(armscontrolsupport ~ liberaldemocracy
                          + log(gdppc) + log(tradeopenness) + conflict
                          + category + globallyrelevant + log(salience + 1)
                          | country + year,
                          cluster = c("country", "year"),
                          data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_fe_con)
save(modelmain_fe_con, file = "modelmain_fe_con.RData")


# Table A8: Fixed Effects Models (incl. Resolution-Level)

modelmain_fe2_all <- feols(armscontrolsupport ~ liberaldemocracy
                           + log(gdppc) + log(tradeopenness) + conflict
                           + log(salience + 1)
                           | country + year + repeatedres,
                           cluster = c("country", "year", "repeatedres"),
                           data = data)
summary(modelmain_fe2_all)
save(modelmain_fe2_all, file = "modelmain_fe2_all.RData")

modelmain_fe2_nuc <- feols(armscontrolsupport ~ liberaldemocracy
                           + log(gdppc) + log(tradeopenness) + conflict
                           + log(salience + 1)
                           | country + year + repeatedres,
                           cluster = c("country", "year", "repeatedres"),
                           data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_fe2_nuc)
save(modelmain_fe2_nuc, file = "modelmain_fe2_nuc.RData")

modelmain_fe2_con <- feols(armscontrolsupport ~ liberaldemocracy
                           + log(gdppc) + log(tradeopenness) + conflict
                           + log(salience + 1)
                           | country + year + repeatedres,
                           cluster = c("country", "year", "repeatedres"),
                           data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_fe2_con)
save(modelmain_fe2_con, file = "modelmain_fe2_con.RData")


# Table A9: Ordered Probit Models

data$armscontrolsupportordinal <- as.ordered(data$armscontrolsupport)

modelmain_ordinal_all <- clmm(armscontrolsupportordinal ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data, link = "probit")
summary(modelmain_ordinal_all)
save(modelmain_ordinal_all, file = "modelmain_ordinal_all.RData")

modelmain_ordinal_nuc <- clmm(armscontrolsupportordinal ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons", ],
                              link = "probit")
summary(modelmain_ordinal_nuc)
save(modelmain_ordinal_nuc, file = "modelmain_ordinal_nuc.RData")

modelmain_ordinal_con <- clmm(armscontrolsupportordinal ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic 
                                          == "Conventional Weapons", ],
                              link = "probit")
summary(modelmain_ordinal_con)
save(modelmain_ordinal_con, file = "modelmain_ordinal_con.RData")


# Table A10: Logit Models 

data$armscontrolsupportbinary <- ifelse(data$armscontrolsupport == 0
                                        | data$armscontrolsupport == 0.5, 0, 1)

modelmain_binary_all <- glmer(armscontrolsupportbinary ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data, family = binomial(link = "logit"),
                              control = glmerControl(optimizer = "bobyqa",
                                                     optCtrl 
                                                     = list(maxfun = 100000)))
summary(modelmain_binary_all)
save(modelmain_binary_all, file = "modelmain_binary_all.RData")

modelmain_binary_nuc <- glmer(armscontrolsupportbinary ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons", ],
                              family = binomial(link = "logit"),
                              control = glmerControl(optimizer = "bobyqa",
                                                     optCtrl 
                                                     = list(maxfun = 100000)))
summary(modelmain_binary_nuc)
save(modelmain_binary_nuc, file = "modelmain_binary_nuc.RData")

modelmain_binary_con <- glmer(armscontrolsupportbinary ~ liberaldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic 
                                          == "Conventional Weapons", ],
                              family = binomial(link = "logit"),
                              control = glmerControl(optimizer = "bobyqa",
                                                     optCtrl 
                                                     = list(maxfun = 100000)))
summary(modelmain_binary_con)
save(modelmain_binary_con, file = "modelmain_binary_con.RData")


# Table A11: EDI as Independent Variable 

modelmain_elecdem_all <- lmer(armscontrolsupport ~ electoraldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic 
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data)
summary(modelmain_elecdem_all)
save(modelmain_elecdem_all, file = "modelmain_elecdem_all.RData")

modelmain_elecdem_nuc <- lmer(armscontrolsupport ~ electoraldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_elecdem_nuc)
save(modelmain_elecdem_nuc, file = "modelmain_elecdem_nuc.RData")

modelmain_elecdem_con <- lmer(armscontrolsupport ~ electoraldemocracy
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region 
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic 
                                          == "Conventional Weapons", ])
summary(modelmain_elecdem_con)
save(modelmain_elecdem_con, file = "modelmain_elecdem_con.RData")


# Table A12: P5 as Independent Variable

modelmain_p5_all <- lmer(armscontrolsupport ~ p5
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + topic 
                         + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data)
summary(modelmain_p5_all)
save(modelmain_p5_all, file = "modelmain_p5_all.RData")

modelmain_p5_nuc <- lmer(armscontrolsupport ~ p5
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_p5_nuc)
save(modelmain_p5_nuc, file = "modelmain_p5_nuc.RData")

modelmain_p5_con <- lmer(armscontrolsupport ~ p5
                         + log(gdppc) + log(tradeopenness) + conflict + region 
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_p5_con)
save(modelmain_p5_con, file = "modelmain_p5_con.RData")


# Table A13: BMR as Independent Variable 

modelmain_bmr_all <- lmer(armscontrolsupport ~ bmr
                          + log(gdppc) + log(tradeopenness) + conflict + region
                          + category + topic 
                          + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data)
summary(modelmain_bmr_all)
save(modelmain_bmr_all, file = "modelmain_bmr_all.RData")

modelmain_bmr_nuc <- lmer(armscontrolsupport ~ bmr
                          + log(gdppc) + log(tradeopenness) + conflict + region
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_bmr_nuc)
save(modelmain_bmr_nuc, file = "modelmain_bmr_nuc.RData")

modelmain_bmr_con <- lmer(armscontrolsupport ~ bmr
                          + log(gdppc) + log(tradeopenness) + conflict + region 
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_bmr_con)
save(modelmain_bmr_con, file = "modelmain_bmr_con.RData")


# Table A14: FH as Independent Variable 

modelmain_fh_all <- lmer(armscontrolsupport ~ fh
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + topic 
                         + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data)
summary(modelmain_fh_all)
save(modelmain_fh_all, file = "modelmain_fh_all.RData")

modelmain_fh_nuc <- lmer(armscontrolsupport ~ fh
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_fh_nuc)
save(modelmain_fh_nuc, file = "modelmain_fh_nuc.RData")

modelmain_fh_con <- lmer(armscontrolsupport ~ fh
                         + log(gdppc) + log(tradeopenness) + conflict + region 
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_fh_con)
save(modelmain_fh_con, file = "modelmain_fh_con.RData")


# Table A15: Excluding Categories 3 and 4

modelmain_cat12_all <- lmer(armscontrolsupport ~ liberaldemocracy
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + topic 
                            + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$category == "1" 
                                        | data$category == "2", ])
summary(modelmain_cat12_all)
save(modelmain_cat12_all, file = "modelmain_cat12_all.RData")

modelmain_cat12_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Nuclear Weapons" 
                                        & data$category == "1" 
                                        | data$topic == "Nuclear Weapons" 
                                        & data$category == "2", ])
summary(modelmain_cat12_nuc)
save(modelmain_cat12_nuc, file = "modelmain_cat12_nuc.RData")

modelmain_cat12_con <- lmer(armscontrolsupport ~ liberaldemocracy
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region 
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Conventional Weapons" 
                                        & data$category == "1" 
                                        | data$topic == "Conventional Weapons" 
                                        & data$category == "2", ])
summary(modelmain_cat12_con)
save(modelmain_cat12_con, file = "modelmain_cat12_con.RData")


# Table A16: Country-Year as Unit of Analysis 

datacy <- bind_rows(
  data %>% 
    group_by(country, year) %>%
    summarize(topic = "All", armscontrolsupport = mean(armscontrolsupport),
              liberaldemocracy = mean(liberaldemocracy), gdppc = mean(gdppc),
              tradeopenness = mean(tradeopenness), conflict = mean(conflict),
              region = paste(unique(region))),
  data %>% 
    group_by(country, year, topic) %>%
    summarize(armscontrolsupport = mean(armscontrolsupport),
              liberaldemocracy = mean(liberaldemocracy), gdppc = mean(gdppc),
              tradeopenness = mean(tradeopenness), conflict = mean(conflict),
              region = paste(unique(region))))

modelmain_countryyear_all <- lmer(armscontrolsupport ~ liberaldemocracy
                                  + log(gdppc) + log(tradeopenness)
                                  + conflict + region
                                  + (1 | country) + (1 | year),
                                  data = datacy[datacy$topic == "All", ])
summary(modelmain_countryyear_all)
save(modelmain_countryyear_all, file = "modelmain_countryyear_all.RData")

modelmain_countryyear_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                                  + log(gdppc) + log(tradeopenness)
                                  + conflict + region
                                  + (1 | country) + (1 | year),
                                  data = datacy[datacy$topic 
                                                == "Nuclear Weapons", ])
summary(modelmain_countryyear_nuc)
save(modelmain_countryyear_nuc, file = "modelmain_countryyear_nuc.RData")

modelmain_countryyear_con <- lmer(armscontrolsupport ~ liberaldemocracy
                                  + log(gdppc) + log(tradeopenness)
                                  + conflict + region
                                  + (1 | country) + (1 | year),
                                  data = datacy[datacy$topic 
                                                == "Conventional Weapons", ])
summary(modelmain_countryyear_con)
save(modelmain_countryyear_con, file = "modelmain_countryyear_con.RData")


# Table A17: Excluding Africa 

modelmain_noafrica_all <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region
                               + category + topic 
                               + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$region != "Africa", ])
summary(modelmain_noafrica_all)
save(modelmain_noafrica_all, file = "modelmain_noafrica_all.RData")

modelmain_noafrica_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region
                               + category + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$topic == "Nuclear Weapons"
                                           & data$region != "Africa", ])
summary(modelmain_noafrica_nuc)
save(modelmain_noafrica_nuc, file = "modelmain_noafrica_nuc.RData")

modelmain_noafrica_con <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness)
                               + conflict + region 
                               + category + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$topic == "Conventional Weapons"
                                           & data$region != "Africa", ])
summary(modelmain_noafrica_con)
save(modelmain_noafrica_con, file = "modelmain_noafrica_con.RData")


# Table A18: Excluding Americas

modelmain_noamericas_all <- lmer(armscontrolsupport ~ liberaldemocracy
                                 + log(gdppc) + log(tradeopenness) 
                                 + conflict + region
                                 + category + topic 
                                 + globallyrelevant + log(salience + 1)
                                 + (1 | country) + (1 | year) 
                                 + (1 | repeatedres),
                                 data = data[data$region != "Americas", ])
summary(modelmain_noamericas_all)
save(modelmain_noamericas_all, file = "modelmain_noamericas_all.RData")

modelmain_noamericas_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                                 + log(gdppc) + log(tradeopenness) 
                                 + conflict + region
                                 + category + globallyrelevant 
                                 + log(salience + 1)
                                 + (1 | country) + (1 | year) 
                                 + (1 | repeatedres),
                                 data = data[data$topic == "Nuclear Weapons" 
                                             & data$region != "Americas", ])
summary(modelmain_noamericas_nuc)
save(modelmain_noamericas_nuc, file = "modelmain_noamericas_nuc.RData")

modelmain_noamericas_con <- lmer(armscontrolsupport ~ liberaldemocracy
                                 + log(gdppc) + log(tradeopenness) 
                                 + conflict + region 
                                 + category + globallyrelevant 
                                 + log(salience + 1)
                                 + (1 | country) + (1 | year) 
                                 + (1 | repeatedres),
                                 data = data[data$topic 
                                             == "Conventional Weapons"
                                             & data$region != "Americas", ])
summary(modelmain_noamericas_con)
save(modelmain_noamericas_con, file = "modelmain_noamericas_con.RData")


# Table A19: Excluding Asia

modelmain_noasia_all <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + topic 
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$region != "Asia", ])
summary(modelmain_noasia_all)
save(modelmain_noasia_all, file = "modelmain_noasia_all.RData")

modelmain_noasia_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons" 
                                         & data$region != "Asia", ])
summary(modelmain_noasia_nuc)
save(modelmain_noasia_nuc, file = "modelmain_noasia_nuc.RData")

modelmain_noasia_con <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region 
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Conventional Weapons"
                                         & data$region != "Asia", ])
summary(modelmain_noasia_con)
save(modelmain_noasia_con, file = "modelmain_noasia_con.RData")


# Table A20: Excluding Europe 

modelmain_noeurope_all <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region
                               + category + topic 
                               + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$region != "Europe", ])
summary(modelmain_noeurope_all)
save(modelmain_noeurope_all, file = "modelmain_noeurope_all.RData")

modelmain_noeurope_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region
                               + category + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$topic == "Nuclear Weapons" 
                                           & data$region != "Europe", ])
summary(modelmain_noeurope_nuc)
save(modelmain_noeurope_nuc, file = "modelmain_noeurope_nuc.RData")

modelmain_noeurope_con <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region 
                               + category + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$topic == "Conventional Weapons"
                                           & data$region != "Europe", ])
summary(modelmain_noeurope_con)
save(modelmain_noeurope_con, file = "modelmain_noeurope_con.RData")


# Table A21: Excluding Middle East 

modelmain_nomiddleeast_all <- lmer(armscontrolsupport ~ liberaldemocracy
                                   + log(gdppc) + log(tradeopenness) 
                                   + conflict + region
                                   + category + topic 
                                   + globallyrelevant + log(salience + 1)
                                   + (1 | country) + (1 | year) 
                                   + (1 | repeatedres),
                                   data = data[data$region != "Middle East", ])
summary(modelmain_nomiddleeast_all)
save(modelmain_nomiddleeast_all, file = "modelmain_nomiddleeast_all.RData")

modelmain_nomiddleeast_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                                   + log(gdppc) + log(tradeopenness) 
                                   + conflict + region
                                   + category + globallyrelevant 
                                   + log(salience + 1)
                                   + (1 | country) + (1 | year) 
                                   + (1 | repeatedres),
                                   data = data[data$topic == "Nuclear Weapons"
                                               & data$region 
                                               != "Middle East", ])
summary(modelmain_nomiddleeast_nuc)
save(modelmain_nomiddleeast_nuc, file = "modelmain_nomiddleeast_nuc.RData")

modelmain_nomiddleeast_con <- lmer(armscontrolsupport ~ liberaldemocracy
                                   + log(gdppc) + log(tradeopenness)
                                   + conflict + region 
                                   + category + globallyrelevant
                                   + log(salience + 1)
                                   + (1 | country) + (1 | year)
                                   + (1 | repeatedres),
                                   data = data[data$topic 
                                               == "Conventional Weapons"
                                               & data$region 
                                               != "Middle East", ])
summary(modelmain_nomiddleeast_con)
save(modelmain_nomiddleeast_con, file = "modelmain_nomiddleeast_con.RData")


# Table A22: Excluding NATO Members 

modelmain_nonato_all <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + topic 
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$nato == 0, ])
summary(modelmain_nonato_all)
save(modelmain_nonato_all, file = "modelmain_nonato_all.RData")

modelmain_nonato_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons"
                                         & data$nato == 0, ])
summary(modelmain_nonato_nuc)
save(modelmain_nonato_nuc, file = "modelmain_nonato_nuc.RData")

modelmain_nonato_con <- lmer(armscontrolsupport ~ liberaldemocracy
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region 
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Conventional Weapons"
                                         & data$nato == 0, ])
summary(modelmain_nonato_con)
save(modelmain_nonato_con, file = "modelmain_nonato_con.RData")


# Table A23: Excluding Consensus Decisions

modelmain_rollcall_all <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region
                               + category + topic 
                               + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$recorded == 1, ])
summary(modelmain_rollcall_all)
save(modelmain_rollcall_all, file = "modelmain_rollcall_all.RData")

modelmain_rollcall_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region
                               + category + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$topic == "Nuclear Weapons"
                                           & data$recorded == 1, ])
summary(modelmain_rollcall_nuc)
save(modelmain_rollcall_nuc, file = "modelmain_rollcall_nuc.RData")

modelmain_rollcall_con <- lmer(armscontrolsupport ~ liberaldemocracy
                               + log(gdppc) + log(tradeopenness) 
                               + conflict + region 
                               + category + globallyrelevant + log(salience + 1)
                               + (1 | country) + (1 | year) + (1 | repeatedres),
                               data = data[data$topic == "Conventional Weapons"
                                           & data$recorded == 1, ])
summary(modelmain_rollcall_con)
save(modelmain_rollcall_con, file = "modelmain_rollcall_con.RData")


# Table A24: Lagging Country-Year Level Variables by One Year

modelmain_lag_all <- lmer(armscontrolsupport ~ liberaldemocracylag
                          + log(gdppclag) + log(tradeopennesslag) 
                          + conflictlag + region
                          + category + topic
                          + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data)
summary(modelmain_lag_all)
save(modelmain_lag_all, file = "modelmain_lag_all.RData")

modelmain_lag_nuc <- lmer(armscontrolsupport ~ liberaldemocracylag
                          + log(gdppclag) + log(tradeopennesslag) 
                          + conflictlag + region
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_lag_nuc)
save(modelmain_lag_nuc, file = "modelmain_lag_nuc.RData")

modelmain_lag_con <- lmer(armscontrolsupport ~ liberaldemocracylag
                          + log(gdppclag) + log(tradeopennesslag) 
                          + conflictlag + region 
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_lag_con)
save(modelmain_lag_con, file = "modelmain_lag_con.RData")


### Online Appendix F: Robustness Checks - Interaction Effect ##################

# Table A25: No Control Variables

modelint_onlyre_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data[data$category == "1"
                                 | data$category == "2", ])
summary(modelint_onlyre_all)
save(modelint_onlyre_all, file = "modelint_onlyre_all.RData")

modelint_onlyre_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Nuclear Weapons" 
                                        & data$category == "1" 
                                        | data$topic == "Nuclear Weapons" 
                                        & data$category == "2", ])
summary(modelint_onlyre_nuc)
save(modelint_onlyre_nuc, file = "modelint_onlyre_nuc.RData")

modelint_onlyre_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Conventional Weapons" 
                                        & data$category == "1" 
                                        | data$topic == "Conventional Weapons" 
                                        & data$category == "2", ])
summary(modelint_onlyre_con)
save(modelint_onlyre_con, file = "modelint_onlyre_con.RData")


# Table A26: Controlling for Nuclear Weapons Possession 

modelint_inclnuc_all <- lmer(armscontrolsupport ~ liberaldemocracy
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region + nuclearpower
                             + category + topic 
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$category == "1" 
                                         | data$category == "2", ])
summary(modelint_inclnuc_all)
save(modelint_inclnuc_all, file = "modelint_inclnuc_all.RData")

modelint_inclnuc_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region + nuclearpower
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Nuclear Weapons" 
                                         & data$category == "2", ])
summary(modelint_inclnuc_nuc)
save(modelint_inclnuc_nuc, file = "modelint_inclnuc_nuc.RData")

modelint_inclnuc_con <- lmer(armscontrolsupport ~ liberaldemocracy
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region + nuclearpower
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Conventional Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Conventional Weapons" 
                                         & data$category == "2", ])
summary(modelint_inclnuc_con)
save(modelint_inclnuc_con, file = "modelint_inclnuc_con.RData")


# Table A27: Controlling for UNGA Ideal Points

modelint_inclid_all <- lmer(armscontrolsupport ~ liberaldemocracy
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region + idealpoint
                            + category + topic
                            + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$category == "1" 
                                        | data$category == "2", ])
summary(modelint_inclid_all)
save(modelint_inclid_all, file = "modelint_inclid_all.RData")

modelint_inclid_nuc <- lmer(armscontrolsupport ~ liberaldemocracy
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region + idealpoint
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Nuclear Weapons" 
                                        & data$category == "1" 
                                        | data$topic == "Nuclear Weapons" 
                                        & data$category == "2", ])
summary(modelint_inclid_nuc)
save(modelint_inclid_nuc, file = "modelint_inclid_nuc.RData")

modelint_inclid_con <- lmer(armscontrolsupport ~ liberaldemocracy
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region + idealpoint
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Conventional Weapons" 
                                        & data$category == "1" 
                                        | data$topic == "Conventional Weapons" 
                                        & data$category == "2", ])
summary(modelint_inclid_con)
save(modelint_inclid_con, file = "modelint_inclid_con.RData")


# Table A28: Fixed Effects Models

modelint_fe_all <- feols(armscontrolsupport ~ liberaldemocracy 
                         * share_libdemauthors
                         + log(gdppc) + log(tradeopenness) + conflict
                         + category + topic
                         + globallyrelevant + log(salience + 1)
                         | country + year,
                         cluster = c("country", "year"),
                         data[data$category == "1" | data$category == "2", ])
summary(modelint_fe_all)
save(modelint_fe_all, file = "modelint_fe_all.RData")

modelint_fe_nuc <- feols(armscontrolsupport ~ liberaldemocracy 
                         * share_libdemauthors
                         + log(gdppc) + log(tradeopenness) + conflict
                         + category + globallyrelevant + log(salience + 1)
                         | country + year,
                         cluster = c("country", "year"),
                         data = data[data$topic == "Nuclear Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Nuclear Weapons" 
                                     & data$category == "2", ])
summary(modelint_fe_nuc)
save(modelint_fe_nuc, file = "modelint_fe_nuc.RData")

modelint_fe_con <- feols(armscontrolsupport ~ liberaldemocracy 
                         * share_libdemauthors
                         + log(gdppc) + log(tradeopenness) + conflict
                         + category + globallyrelevant + log(salience + 1)
                         | country + year,
                         cluster = c("country", "year"),
                         data = data[data$topic == "Conventional Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Conventional Weapons" 
                                     & data$category == "2", ])
summary(modelint_fe_con)
save(modelint_fe_con, file = "modelint_fe_con.RData")


# Table A29: Fixed Effects Models (incl. Resolution-Level)

modelint_fe2_all <- feols(armscontrolsupport ~ liberaldemocracy 
                          * share_libdemauthors
                          + log(gdppc) + log(tradeopenness) + conflict
                          + log(salience + 1)
                          | country + year + repeatedres,
                          cluster = c("country", "year", "repeatedres"),
                          data[data$category == "1" | data$category == "2", ])
summary(modelint_fe2_all)
save(modelint_fe2_all, file = "modelint_fe2_all.RData")

modelint_fe2_nuc <- feols(armscontrolsupport ~ liberaldemocracy 
                          * share_libdemauthors
                          + log(gdppc) + log(tradeopenness) + conflict
                          + log(salience + 1)
                          | country + year + repeatedres,
                          cluster = c("country", "year", "repeatedres"),
                          data = data[data$topic == "Nuclear Weapons" 
                                      & data$category == "1" 
                                      | data$topic == "Nuclear Weapons" 
                                      & data$category == "2", ])
summary(modelint_fe2_nuc)
save(modelint_fe2_nuc, file = "modelint_fe2_nuc.RData")

modelint_fe2_con <- feols(armscontrolsupport ~ liberaldemocracy 
                          * share_libdemauthors
                          + log(gdppc) + log(tradeopenness) + conflict
                          + log(salience + 1)
                          | country + year + repeatedres,
                          cluster = c("country", "year", "repeatedres"),
                          data = data[data$topic == "Conventional Weapons" 
                                      & data$category == "1" 
                                      | data$topic == "Conventional Weapons" 
                                      & data$category == "2", ])
summary(modelint_fe2_con)
save(modelint_fe2_con, file = "modelint_fe2_con.RData")


# Table A30: Ordered Probit Models 

modelint_ordinal_all <- clmm(armscontrolsupportordinal ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + topic
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data[data$category == "1" 
                                  | data$category == "2", ],
                             link = "probit")
summary(modelint_ordinal_all)
save(modelint_ordinal_all, file = "modelint_ordinal_all.RData")

modelint_ordinal_nuc <- clmm(armscontrolsupportordinal ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Nuclear Weapons" 
                                         & data$category == "2", ],
                             link = "probit")
summary(modelint_ordinal_nuc)
save(modelint_ordinal_nuc, file = "modelint_ordinal_nuc.RData")

modelint_ordinal_con <- clmm(armscontrolsupportordinal ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Conventional Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Conventional Weapons" 
                                         & data$category == "2", ],
                             link = "probit")
summary(modelint_ordinal_con)
save(modelint_ordinal_con, file = "modelint_ordinal_con.RData")


# Table A31: Logit Models 

modelint_binary_all <- glmer(armscontrolsupportbinary ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + topic
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$category == "1" 
                                         | data$category == "2", ], 
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa",
                                                    optCtrl 
                                                    = list(maxfun = 100000)))
summary(modelint_binary_all)
save(modelint_binary_all, file = "modelint_binary_all.RData")

modelint_binary_nuc <- glmer(armscontrolsupportbinary ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Nuclear Weapons" 
                                         & data$category == "2", ],
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa",
                                                    optCtrl 
                                                    = list(maxfun = 100000)))
summary(modelint_binary_nuc)
save(modelint_binary_nuc, file = "modelint_binary_nuc.RData")

modelint_binary_con <- glmer(armscontrolsupportbinary ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Conventional Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Conventional Weapons" 
                                         & data$category == "2", ],
                             family = binomial(link = "logit"),
                             control = glmerControl(optimizer = "bobyqa",
                                                    optCtrl 
                                                    = list(maxfun = 100000)))
summary(modelint_binary_con)
save(modelint_binary_con, file = "modelint_binary_con.RData")


# Table A32: EDI as Independent Variable 

modelint_elecdem_all <- lmer(armscontrolsupport ~ electoraldemocracy 
                             * share_elecdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + topic 
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data[data$category == "1" 
                                  | data$category == "2", ])
summary(modelint_elecdem_all)
save(modelint_elecdem_all, file = "modelint_elecdem_all.RData")

modelint_elecdem_nuc <- lmer(armscontrolsupport ~ electoraldemocracy 
                             * share_elecdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Nuclear Weapons" 
                                         & data$category == "2", ])
summary(modelint_elecdem_nuc)
save(modelint_elecdem_nuc, file = "modelint_elecdem_nuc.RData")

modelint_elecdem_con <- lmer(armscontrolsupport ~ electoraldemocracy 
                             * share_elecdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region 
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Conventional Weapons" 
                                         & data$category == "1" 
                                         | data$topic == "Conventional Weapons" 
                                         & data$category == "2", ])
summary(modelint_elecdem_con)
save(modelint_elecdem_con, file = "modelint_elecdem_con.RData")


# Table A33: P5 as Independent Variable 

modelint_p5_all <- lmer(armscontrolsupport ~ p5 * share_p5authors
                        + log(gdppc) + log(tradeopenness) + conflict + region
                        + category + topic 
                        + globallyrelevant + log(salience + 1)
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data[data$category == "1" | data$category == "2", ])
summary(modelint_p5_all)
save(modelint_p5_all, file = "modelint_p5_all.RData")

modelint_p5_nuc <- lmer(armscontrolsupport ~ p5 * share_p5authors
                        + log(gdppc) + log(tradeopenness) + conflict + region
                        + category + globallyrelevant + log(salience + 1)
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data[data$topic == "Nuclear Weapons" 
                                    & data$category == "1" 
                                    | data$topic == "Nuclear Weapons" 
                                    & data$category == "2", ])
summary(modelint_p5_nuc)
save(modelint_p5_nuc, file = "modelint_p5_nuc.RData")

modelint_p5_con <- lmer(armscontrolsupport ~ p5 * share_p5authors
                        + log(gdppc) + log(tradeopenness) + conflict + region 
                        + category + globallyrelevant + log(salience + 1)
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data[data$topic == "Conventional Weapons" 
                                    & data$category == "1" 
                                    | data$topic == "Conventional Weapons" 
                                    & data$category == "2", ])
summary(modelint_p5_con)
save(modelint_p5_con, file = "modelint_p5_con.RData")


# Table A34: BMR as Independent Variable 

modelint_bmr_all <- lmer(armscontrolsupport ~ bmr * share_bmrauthors
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + topic 
                         + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data[data$category == "1" | data$category == "2", ])
summary(modelint_bmr_all)
save(modelint_bmr_all, file = "modelint_bmr_all.RData")

modelint_bmr_nuc <- lmer(armscontrolsupport ~ bmr * share_bmrauthors
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Nuclear Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Nuclear Weapons" 
                                     & data$category == "2", ])
summary(modelint_bmr_nuc)
save(modelint_bmr_nuc, file = "modelint_bmr_nuc.RData")

modelint_bmr_con <- lmer(armscontrolsupport ~ bmr * share_bmrauthors
                         + log(gdppc) + log(tradeopenness) + conflict + region 
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Conventional Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Conventional Weapons" 
                                     & data$category == "2", ])
summary(modelint_bmr_con)
save(modelint_bmr_con, file = "modelint_bmr_con.RData")


# Table A35: FH as Independent Variable 

modelint_fh_all <- lmer(armscontrolsupport ~ fh * share_fhauthors
                        + log(gdppc) + log(tradeopenness) + conflict + region
                        + category + topic 
                        + globallyrelevant + log(salience + 1)
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data[data$category == "1" | data$category == "2", ])
summary(modelint_fh_all)
save(modelint_fh_all, file = "modelint_fh_all.RData")

modelint_fh_nuc <- lmer(armscontrolsupport ~ fh * share_fhauthors
                        + log(gdppc) + log(tradeopenness) + conflict + region
                        + category + globallyrelevant + log(salience + 1)
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data[data$topic == "Nuclear Weapons" 
                                    & data$category == "1" 
                                    | data$topic == "Nuclear Weapons" 
                                    & data$category == "2", ])
summary(modelint_fh_nuc)
save(modelint_fh_nuc, file = "modelint_fh_nuc.RData")

modelint_fh_con <- lmer(armscontrolsupport ~ fh * share_fhauthors
                        + log(gdppc) + log(tradeopenness) + conflict + region 
                        + category + globallyrelevant + log(salience + 1)
                        + (1 | country) + (1 | year) + (1 | repeatedres),
                        data = data[data$topic == "Conventional Weapons" 
                                    & data$category == "1" 
                                    | data$topic == "Conventional Weapons" 
                                    & data$category == "2", ])
summary(modelint_fh_con)
save(modelint_fh_con, file = "modelint_fh_con.RData")


# Table A36: Excluding Africa 

modelint_noafrica_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic 
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$region != "Africa" 
                                          & data$category == "1" 
                                          | data$region != "Africa" 
                                          & data$category == "2", ])
summary(modelint_noafrica_all)
save(modelint_noafrica_all, file = "modelint_noafrica_all.RData")

modelint_noafrica_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons" 
                                          & data$region != "Africa" 
                                          & data$category == "1" 
                                          | data$topic == "Nuclear Weapons" 
                                          & data$region != "Africa" 
                                          & data$category == "2", ])
summary(modelint_noafrica_nuc)
save(modelint_noafrica_nuc, file = "modelint_noafrica_nuc.RData")

modelint_noafrica_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness)
                              + conflict + region 
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Conventional Weapons" 
                                          & data$region != "Africa" 
                                          & data$category == "1" 
                                          | data$topic == "Conventional Weapons" 
                                          & data$region != "Africa" 
                                          & data$category == "2", ])
summary(modelint_noafrica_con)
save(modelint_noafrica_con, file = "modelint_noafrica_con.RData")


# Table A37: Excluding Americas

modelint_noamericas_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                                * share_libdemauthors
                                + log(gdppc) + log(tradeopenness) 
                                + conflict + region
                                + category + topic 
                                + globallyrelevant + log(salience + 1)
                                + (1 | country) + (1 | year) 
                                + (1 | repeatedres),
                                data = data[data$region != "Americas" 
                                            & data$category == "1" 
                                            | data$region != "Americas" 
                                            & data$category == "2", ])
summary(modelint_noamericas_all)
save(modelint_noamericas_all, file = "modelint_noamericas_all.RData")

modelint_noamericas_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                                * share_libdemauthors
                                + log(gdppc) + log(tradeopenness) 
                                + conflict + region
                                + category + globallyrelevant 
                                + log(salience + 1)
                                + (1 | country) + (1 | year) 
                                + (1 | repeatedres),
                                data = data[data$topic == "Nuclear Weapons" 
                                            & data$region != "Americas" 
                                            & data$category == "1" 
                                            | data$topic == "Nuclear Weapons" 
                                            & data$region != "Americas" 
                                            & data$category == "2", ])
summary(modelint_noamericas_nuc)
save(modelint_noamericas_nuc, file = "modelint_noamericas_nuc.RData")

modelint_noamericas_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                                * share_libdemauthors
                                + log(gdppc) + log(tradeopenness) 
                                + conflict + region 
                                + category + globallyrelevant 
                                + log(salience + 1)
                                + (1 | country) + (1 | year) 
                                + (1 | repeatedres),
                                data = data[data$topic == "Conventional Weapons" 
                                            & data$region != "Americas" 
                                            & data$category == "1" 
                                            | data$topic 
                                            == "Conventional Weapons" 
                                            & data$region != "Americas" 
                                            & data$category == "2", ])
summary(modelint_noamericas_con)
save(modelint_noamericas_con, file = "modelint_noamericas_con.RData")


# Table A38: Excluding Asia

modelint_noasia_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + topic 
                            + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$region != "Asia" 
                                        & data$category == "1" 
                                        | data$region != "Asia" 
                                        & data$category == "2", ])
summary(modelint_noasia_all)
save(modelint_noasia_all, file = "modelint_noasia_all.RData")

modelint_noasia_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Nuclear Weapons" 
                                        & data$region != "Asia" 
                                        & data$category == "1" 
                                        | data$topic == "Nuclear Weapons" 
                                        & data$region != "Asia" 
                                        & data$category == "2", ])
summary(modelint_noasia_nuc)
save(modelint_noasia_nuc, file = "modelint_noasia_nuc.RData")

modelint_noasia_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region 
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Conventional Weapons" 
                                        & data$region != "Asia" 
                                        & data$category == "1" 
                                        | data$topic == "Conventional Weapons" 
                                        & data$region != "Asia" 
                                        & data$category == "2", ])
summary(modelint_noasia_con)
save(modelint_noasia_con, file = "modelint_noasia_con.RData")


# Table A39: Excluding Europe 

modelint_noeurope_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic 
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$region != "Europe" 
                                          & data$category == "1" 
                                          | data$region != "Europe" 
                                          & data$category == "2", ])
summary(modelint_noeurope_all)
save(modelint_noeurope_all, file = "modelint_noeurope_all.RData")

modelint_noeurope_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons" 
                                          & data$region != "Europe" 
                                          & data$category == "1" 
                                          | data$topic == "Nuclear Weapons" 
                                          & data$region != "Europe" 
                                          & data$category == "2", ])
summary(modelint_noeurope_nuc)
save(modelint_noeurope_nuc, file = "modelint_noeurope_nuc.RData")

modelint_noeurope_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region 
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Conventional Weapons" 
                                          & data$region != "Europe" 
                                          & data$category == "1" 
                                          | data$topic == "Conventional Weapons" 
                                          & data$region != "Europe" 
                                          & data$category == "2", ])
summary(modelint_noeurope_con)
save(modelint_noeurope_con, file = "modelint_noeurope_con.RData")


# Table A40: Excluding Middle East 

modelint_nomiddleeast_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                                  * share_libdemauthors
                                  + log(gdppc) + log(tradeopenness) 
                                  + conflict + region
                                  + category + topic 
                                  + globallyrelevant + log(salience + 1)
                                  + (1 | country) + (1 | year) 
                                  + (1 | repeatedres),
                                  data = data[data$region != "Middle East" 
                                              & data$category == "1" 
                                              | data$region != "Middle East" 
                                              & data$category == "2", ])
summary(modelint_nomiddleeast_all)
save(modelint_nomiddleeast_all, file = "modelint_nomiddleeast_all.RData")

modelint_nomiddleeast_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                                  * share_libdemauthors
                                  + log(gdppc) + log(tradeopenness) 
                                  + conflict + region
                                  + category + globallyrelevant 
                                  + log(salience + 1)
                                  + (1 | country) + (1 | year) 
                                  + (1 | repeatedres),
                                  data = data[data$topic == "Nuclear Weapons" 
                                              & data$region != "Middle East" 
                                              & data$category == "1" 
                                              | data$topic == "Nuclear Weapons" 
                                              & data$region != "Middle East" 
                                              & data$category == "2", ])
summary(modelint_nomiddleeast_nuc)
save(modelint_nomiddleeast_nuc, file = "modelint_nomiddleeast_nuc.RData")

modelint_nomiddleeast_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                                  * share_libdemauthors
                                  + log(gdppc) + log(tradeopenness)
                                  + conflict + region 
                                  + category + globallyrelevant
                                  + log(salience + 1)
                                  + (1 | country) + (1 | year)
                                  + (1 | repeatedres),
                                  data = data[data$topic 
                                              == "Conventional Weapons" 
                                              & data$region != "Middle East" 
                                              & data$category == "1" 
                                              | data$topic 
                                              == "Conventional Weapons" 
                                              & data$region != "Middle East" 
                                              & data$category == "2", ])
summary(modelint_nomiddleeast_con)
save(modelint_nomiddleeast_con, file = "modelint_nomiddleeast_con.RData")


# Table A41: Excluding NATO Members 

modelint_nonato_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + topic 
                            + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$nato == 0 & data$category == "1" 
                                        | data$nato == 0 
                                        & data$category == "2", ])
summary(modelint_nonato_all)
save(modelint_nonato_all, file = "modelint_nonato_all.RData")

modelint_nonato_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Nuclear Weapons"
                                        & data$nato == 0 
                                        & data$category == "1" 
                                        | data$topic == "Nuclear Weapons"
                                        & data$nato == 0 
                                        & data$category == "2", ])
summary(modelint_nonato_nuc)
save(modelint_nonato_nuc, file = "modelint_nonato_nuc.RData")

modelint_nonato_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                            * share_libdemauthors
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region 
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Conventional Weapons"
                                        & data$nato == 0 & data$category == "1" 
                                        | data$topic == "Conventional Weapons"
                                        & data$nato == 0 
                                        & data$category == "2", ])
summary(modelint_nonato_con)
save(modelint_nonato_con, file = "modelint_nonato_con.RData")


# Table A42: Excluding Consensus Decisions

modelint_rollcall_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic 
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$recorded == 1 
                                          & data$category == "1" 
                                          | data$recorded == 1 
                                          & data$category == "2", ])
summary(modelint_rollcall_all)
save(modelint_rollcall_all, file = "modelint_rollcall_all.RData")

modelint_rollcall_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons"
                                          & data$recorded == 1 
                                          & data$category == "1" 
                                          | data$topic == "Nuclear Weapons"
                                          & data$recorded == 1 
                                          & data$category == "2", ])
summary(modelint_rollcall_nuc)
save(modelint_rollcall_nuc, file = "modelint_rollcall_nuc.RData")

modelint_rollcall_con <- lmer(armscontrolsupport ~ liberaldemocracy 
                              * share_libdemauthors
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region 
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Conventional Weapons"
                                          & data$recorded == 1 
                                          & data$category == "1" 
                                          | data$topic == "Conventional Weapons"
                                          & data$recorded == 1 
                                          & data$category == "2", ])
summary(modelint_rollcall_con)
save(modelint_rollcall_con, file = "modelint_rollcall_con.RData")


# Table A43: Lagging Country-Year Level Variables by One Year

modelint_lag_all <- lmer(armscontrolsupport ~ liberaldemocracylag 
                         * share_libdemauthors
                         + log(gdppclag) + log(tradeopennesslag) 
                         + conflictlag + region
                         + category + topic 
                         + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data[data$category == "1" | data$category == "2", ])
summary(modelint_lag_all)
save(modelint_lag_all, file = "modelint_lag_all.RData")

modelint_lag_nuc <- lmer(armscontrolsupport ~ liberaldemocracylag 
                         * share_libdemauthors
                         + log(gdppclag) + log(tradeopennesslag) 
                         + conflictlag + region
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Nuclear Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Nuclear Weapons" 
                                     & data$category == "2", ])
summary(modelint_lag_nuc)
save(modelint_lag_nuc, file = "modelint_lag_nuc.RData")

modelint_lag_con <- lmer(armscontrolsupport ~ liberaldemocracylag 
                         * share_libdemauthors
                         + log(gdppclag) + log(tradeopennesslag) 
                         + conflictlag + region 
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Conventional Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Conventional Weapons" 
                                     & data$category == "2", ])
summary(modelint_lag_con)
save(modelint_lag_con, file = "modelint_lag_con.RData")


### Online Appendix G: Exploratory Analyses ####################################

# Table A44: Wordscores Top 50 Positive (Democratic) and Negative 
# (Non-Democratic) Terms for Nuclear Arms Control Resolutions

datares <- data %>% group_by(resolution) %>%
  summarize(category = paste(unique(category)), topic = paste(unique(topic)),
            share_libdemauthors = mean(share_libdemauthors),
            text = paste(unique(text)))

datares_nuc <- datares[datares$topic == "Nuclear Weapons" 
                       & datares$category == "1" 
                       | datares$topic == "Nuclear Weapons" 
                       & datares$category == "2", ]
dfm_nuc <- tokens(datares_nuc$text, remove_numbers = T, remove_punct = T,
                  remove_symbols = T, remove_url = T, split_hyphens = T)
dfm_nuc <- tokens_select(dfm_nuc, min_nchar = 3L)
dfm_nuc <- tokens_remove(dfm_nuc, stopwords("english"))
dfm_nuc <- tokens_keep(dfm_nuc, pattern = "^[^0-9]+$", valuetype = "regex")
dfm_nuc <- tokens_remove(dfm_nuc, pattern = "^_+$", valuetype = "regex")
dfm_nuc <- dfm(dfm_nuc)
dfm_nuc <- dfm_wordstem(dfm_nuc)
ws_nuc <- textmodel_wordscores(dfm_nuc, y = datares_nuc$share_libdemauthors,
                               smooth = 1)
ws_nuc <- data.frame(ws_nuc$x@Dimnames$features, ws_nuc$wordscores)
freq_nuc <- textstat_frequency(dfm_nuc)
ws_nuc <- merge(ws_nuc, freq_nuc, by.x = "ws_nuc.x.Dimnames.features",
                by.y = "feature")
print(ws_nuc[order(-ws_nuc$ws_nuc.wordscores), ][1:50, ])
print(ws_nuc[order(ws_nuc$ws_nuc.wordscores), ][1:50, ])
save(ws_nuc, file = "ws_nuc.RData")


# Table A45: Wordscores Top 50 Positive (Democratic) and Negative 
# (Non-Democratic) Terms for Conventional Arms Control Resolutions

datares_con <- datares[datares$topic == "Conventional Weapons" 
                       & datares$category == "1" 
                       | datares$topic == "Conventional Weapons" 
                       & datares$category == "2", ]
dfm_con <- tokens(datares_con$text, remove_punct = T, remove_symbols = T,
                  remove_url = T)
dfm_con <- tokens_select(dfm_con, min_nchar = 3L)
dfm_con <- tokens_remove(dfm_con, stopwords("english"))
dfm_con <- dfm(dfm_con)
dfm_con <- dfm_wordstem(dfm_con)
ws_con <- textmodel_wordscores(dfm_con, y = datares_con$share_libdemauthors,
                               smooth = 1)
ws_con <- data.frame(ws_con$x@Dimnames$features, ws_con$wordscores)
freq_con <- textstat_frequency(dfm_con)
ws_con <- merge(ws_con, freq_con, by.x = "ws_con.x.Dimnames.features",
                by.y = "feature")
print(ws_con[order(-ws_con$ws_con.wordscores), ][1:50, ])
print(ws_con[order(ws_con$ws_con.wordscores), ][1:50, ])
save(ws_con, file = "ws_con.RData")


# Table A46: Keyness Top 100 Terms for Speeches by Non-Democracies Opposing 
# Nuclear Arms Control Resolutions + Table A47: Keyness Top 100 Terms for
# Speeches by Democracies Opposing Nuclear Arms Control Resolutions

load("speeches.RData")

speeches <- speeches[speeches$nuc_nondem_against == 1
                     | speeches$nuc_dem_against == 1, ]
dfmspeech_nuc <- tokens(speeches$text,remove_punct = T, remove_symbols = T,
                        remove_url = T)
dfmspeech_nuc <- tokens_select(dfmspeech_nuc, min_nchar = 3L)
dfmspeech_nuc <- tokens_remove(dfmspeech_nuc, stopwords("english"))
dfmspeech_nuc <- dfm(dfmspeech_nuc)
dfmspeech_nuc <- dfm_wordstem(dfmspeech_nuc)
dfmspeech_nuc <- dfm_group(dfmspeech_nuc,
                           groups = speeches$nuc_nondem_against)
kn_nuc <- textstat_keyness(dfmspeech_nuc, target = "1")
kn_nuc$freq <- kn_nuc$n_target + kn_nuc$n_reference
print(kn_nuc[order(-kn_nuc$chi2), ][1:100, ])
print(kn_nuc[order(kn_nuc$chi2), ][1:100, ])
save(kn_nuc, file = "kn_nuc.RData")


# Table A48: Government Accountability - Main Effect

modelmain_acc_all <- lmer(armscontrolsupport ~ accountability
                          + log(gdppc) + log(tradeopenness) + conflict + region
                          + category + topic 
                          + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data)
summary(modelmain_acc_all)
save(modelmain_acc_all, file = "modelmain_acc_all.RData")

modelmain_acc_nuc <- lmer(armscontrolsupport ~ accountability
                          + log(gdppc) + log(tradeopenness) + conflict + region
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_acc_nuc)
save(modelmain_acc_nuc, file = "modelmain_acc_nuc.RData")

modelmain_acc_con <- lmer(armscontrolsupport ~ accountability
                          + log(gdppc) + log(tradeopenness) + conflict + region 
                          + category + globallyrelevant + log(salience + 1)
                          + (1 | country) + (1 | year) + (1 | repeatedres),
                          data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_acc_con)
save(modelmain_acc_con, file = "modelmain_acc_con.RData")


# Table A49: Democratic Stock - Main Effect

modelmain_stock_all <- lmer(armscontrolsupport ~ stock
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + topic 
                            + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data)
summary(modelmain_stock_all)
save(modelmain_stock_all, file = "modelmain_stock_all.RData")

modelmain_stock_nuc <- lmer(armscontrolsupport ~ stock
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Nuclear Weapons", ])
summary(modelmain_stock_nuc)
save(modelmain_stock_nuc, file = "modelmain_stock_nuc.RData")

modelmain_stock_con <- lmer(armscontrolsupport ~ stock
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region 
                            + category + globallyrelevant + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[data$topic == "Conventional Weapons", ])
summary(modelmain_stock_con)
save(modelmain_stock_con, file = "modelmain_stock_con.RData")


# Table A50: Government Accountability - Interaction Effect 

modelint_acc_all <- lmer(armscontrolsupport ~ accountability 
                         * share_libdemauthors
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + topic 
                         + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data[data$category == "1" | data$category == "2", ])
summary(modelint_acc_all)
save(modelint_acc_all, file = "modelint_acc_all.RData")

modelint_acc_nuc <- lmer(armscontrolsupport ~ accountability 
                         * share_libdemauthors
                         + log(gdppc) + log(tradeopenness) + conflict + region
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Nuclear Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Nuclear Weapons" 
                                     & data$category == "2", ])
summary(modelint_acc_nuc)
save(modelint_acc_nuc, file = "modelint_acc_nuc.RData")

modelint_acc_con <- lmer(armscontrolsupport ~ accountability 
                         * share_libdemauthors
                         + log(gdppc) + log(tradeopenness) + conflict + region 
                         + category + globallyrelevant + log(salience + 1)
                         + (1 | country) + (1 | year) + (1 | repeatedres),
                         data = data[data$topic == "Conventional Weapons" 
                                     & data$category == "1" 
                                     | data$topic == "Conventional Weapons" 
                                     & data$category == "2", ])
summary(modelint_acc_con)
save(modelint_acc_con, file = "modelint_acc_con.RData")


# Table A51: Democratic Stock - Interaction Effect 

modelint_stock_all <- lmer(armscontrolsupport ~ stock * share_libdemauthors
                           + log(gdppc) + log(tradeopenness) + conflict + region
                           + category + topic 
                           + globallyrelevant + log(salience + 1)
                           + (1 | country) + (1 | year) + (1 | repeatedres),
                           data[data$category == "1" | data$category == "2", ])
summary(modelint_stock_all)
save(modelint_stock_all, file = "modelint_stock_all.RData")

modelint_stock_nuc <- lmer(armscontrolsupport ~ stock * share_libdemauthors
                           + log(gdppc) + log(tradeopenness) + conflict + region
                           + category + globallyrelevant + log(salience + 1)
                           + (1 | country) + (1 | year) + (1 | repeatedres),
                           data = data[data$topic == "Nuclear Weapons" 
                                       & data$category == "1" 
                                       | data$topic == "Nuclear Weapons" 
                                       & data$category == "2", ])
summary(modelint_stock_nuc)
save(modelint_stock_nuc, file = "modelint_stock_nuc.RData")

modelint_stock_con <- lmer(armscontrolsupport ~ stock * share_libdemauthors
                           + log(gdppc) + log(tradeopenness) + conflict + region 
                           + category + globallyrelevant + log(salience + 1)
                           + (1 | country) + (1 | year) + (1 | repeatedres),
                           data = data[data$topic == "Conventional Weapons" 
                                       & data$category == "1" 
                                       | data$topic == "Conventional Weapons" 
                                       & data$category == "2", ])
summary(modelint_stock_con)
save(modelint_stock_con, file = "modelint_stock_con.RData")


# Table A52: Excluding Resolutions on Middle East/South Asia NWFZ - Main Effect  

modelmain_nomeres_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic 
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[!grepl("Middle East", data$title), ])
summary(modelmain_nomeres_all)
save(modelmain_nomeres_all, file = "modelmain_nomeres_all.RData")

modelmain_nomeres_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons"
                                          & !grepl("Middle East",
                                                   data$title), ])
summary(modelmain_nomeres_nuc)
save(modelmain_nomeres_nuc, file = "modelmain_nomeres_nuc.RData")

modelmain_nosares_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + topic 
                              + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[!grepl("South Asia", data$title), ])
summary(modelmain_nosares_all)
save(modelmain_nosares_all, file = "modelmain_nosares_all.RData")

modelmain_nosares_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                              + log(gdppc) + log(tradeopenness) 
                              + conflict + region
                              + category + globallyrelevant + log(salience + 1)
                              + (1 | country) + (1 | year) + (1 | repeatedres),
                              data = data[data$topic == "Nuclear Weapons"
                                          & !grepl("South Asia", data$title), ])
summary(modelmain_nosares_nuc)
save(modelmain_nosares_nuc, file = "modelmain_nosares_nuc.RData")


# Table A53: Including Only Resolutions on Middle East/South Asia NWFZ 

modelmain_onlymeres <- lmer(armscontrolsupport ~ liberaldemocracy 
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region + log(salience + 1)
                            + (1 | country) + (1 | year) + (1 | repeatedres),
                            data = data[grepl("Middle East", data$title)
                                        & data$category != "3", ])
summary(modelmain_onlymeres)
save(modelmain_onlymeres, file = "modelmain_onlymeres.RData")

modelmain_onlysares <- lmer(armscontrolsupport ~ liberaldemocracy 
                            + log(gdppc) + log(tradeopenness) 
                            + conflict + region + log(salience + 1)
                            + (1 | country) + (1 | year),
                            data = data[grepl("South Asia", data$title), ])
summary(modelmain_onlysares)
save(modelmain_onlysares, file = "modelmain_onlysares.RData")


# Table A54: Excluding Resolutions on Middle East/South Asia NWFZ - Interaction
# Effect

modelint_nomeres_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + topic 
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$category == "1"
                                         & !grepl("Middle East", data$title)
                                         | data$category == "2"
                                         & !grepl("Middle East", data$title), ])
summary(modelint_nomeres_all)
save(modelint_nomeres_all, file = "modelint_nomeres_all.RData")

modelint_nomeres_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons"
                                         & data$category == "1"
                                         & !grepl("Middle East", data$title)
                                         | data$topic == "Nuclear Weapons"
                                         & data$category == "2"
                                         & !grepl("Middle East", data$title), ])
summary(modelint_nomeres_nuc)
save(modelint_nomeres_nuc, file = "modelint_nomeres_nuc.RData")

modelint_nosares_all <- lmer(armscontrolsupport ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + topic 
                             + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$category == "1"
                                         & !grepl("South Asia", data$title)
                                         | data$category == "2"
                                         & !grepl("South Asia", data$title), ])
summary(modelint_nosares_all)
save(modelint_nosares_all, file = "modelint_nosares_all.RData")

modelint_nosares_nuc <- lmer(armscontrolsupport ~ liberaldemocracy 
                             * share_libdemauthors
                             + log(gdppc) + log(tradeopenness) 
                             + conflict + region
                             + category + globallyrelevant + log(salience + 1)
                             + (1 | country) + (1 | year) + (1 | repeatedres),
                             data = data[data$topic == "Nuclear Weapons"
                                         & data$category == "1"
                                         & !grepl("South Asia", data$title)
                                         | data$topic == "Nuclear Weapons"
                                         & data$category == "2"
                                         & !grepl("South Asia", data$title), ])
summary(modelint_nosares_nuc)
save(modelint_nosares_nuc, file = "modelint_nosares_nuc.RData")
